﻿

function main() {
    showLog("抖音(同城评论点赞)");
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var terminationNum = viewJson.terminationNum;

    // chuSiHua(widget.pages.shouye.bugengxin);
    AccessibilityEngine.sleepEngine(10000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);

    if (AccessibilityEngine.checkUpText("同城")==ISTRUE ) {		
        AccessibilityEngine.mockOnClickIdText("com.ss.android.ugc.aweme:id/den", "同城"); //点击同城
    }else{
	     AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dyx");
	}

    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(3000);//等待
  
	AccessibilityEngine.mockOnClickIdText("com.ss.android.ugc.aweme:id/den", "同城");
    AccessibilityEngine.sleepEngine(1000);//等待
  
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
   
	 if( jixing == 1 ){// 判断机型
		 ScreenEngine.swipe(parseX(614), parseY(861), parseX(614), parseY(861), 500);//第二个视屏
	} else if( jixing == 2 ){
		 AccessibilityEngine.mockOnClickIdIndex(widget.pages.tongchengyemian.shipinxiaoxin, 2);
	}
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }

    AccessibilityEngine.sleepEngine(2000);//等待
    if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/bo_") == ISTRUE) {
        showLog("显示执行成功");
        setTaskState("5", "进入直播间请重发一次");
        throw SyntaxError();
    }else {
        for (var i =0 ; i <search; i ++ ){  // 循环滑动
            AccessibilityEngine.sleepEngine(3000);//等待
            if( jixing == 1 ){// 判断机型
                var pressjixing = "press," + parseX(660) + "," + parseY(757);
                ScreenEngine.currency(pressjixing);
            } else if( jixing == 2 ){
                ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //从下往上滑动
            }
            for (var ii=0 ; ii<=20 ;ii++){// 判断是否进入评论区
                if ( AccessibilityEngine.checkUpText("留下你的精彩评论吧") == ISFALSE){
                    if( jixing == 1 ){
                        var pressjixing = "press," + parseX(660) + "," + parseY(763);
                        ScreenEngine.currency(pressjixing);
                    } else if( jixing == 2 ){
                        ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //从下往上滑动
                    }
                }else {
                    break;
                }
                AccessibilityEngine.sleepEngine(2000);
                if (ii==20){
                    setTaskState("5", "脚本执行完毕");
                    throw SyntaxError();
                }
            }
            if (AccessibilityEngine.checkUpIdText(widget.pages.fasongxiaoxi.plzf, "评论并转发")==ISTRUE){
                showLog("误点评论返回");
                i--;
                AccessibilityEngine.mockBack();
                AccessibilityEngine.sleepEngine(2000);//等待
                AccessibilityEngine.mockBack();
                AccessibilityEngine.sleepEngine(2000);//等待
                ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 1500); //从下往上滑动
                continue;
            }
            AccessibilityEngine.sleepEngine(2000);
            var termination=0;
            aaa:while (termination < terminationNum){
                var nowArray = new Array();
                var hasRunOperate =true;
                if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/bfs") == ISTRUE) { //点赞小心
                    var zanIdNum = AccessibilityEngine.getIdNum("com.ss.android.ugc.aweme:id/bfs");
                    showLog('zanIdNum' + zanIdNum);
                    for (var zan = 0; zan < zanIdNum; zan++) {
                        AccessibilityEngine.sleepEngine(300);//等待
                        AccessibilityEngine.mockOnClickIdIndex("com.ss.android.ugc.aweme:id/bfs", zan); //逐个小心
                        termination++;
                        if (termination >= terminationNum) {
                            AccessibilityEngine.mockBack();
                            break aaa;
                        }
                    }
                    if (AccessibilityEngine.checkUpText("暂时没有更多了") == ISTRUE ) {
                        showLog("暂时没有更多了点击返回");
                        AccessibilityEngine.mockBack();
                        break  aaa;
                    }
                    AccessibilityEngine.sleepEngine(1500);//等待
                    showLog("滑动滑动滑动");
                    ScreenEngine.swipe(parseX(500), parseY(900), parseX(500), parseY(300), 1000);
                    AccessibilityEngine.sleepEngine(1500);//等待
                    ScreenEngine.swipe(parseX(500), parseY(900), parseX(500), parseY(300), 1000);
                }else {
                    AccessibilityEngine.mockBack();
                    break;
                }
            }
            AccessibilityEngine.sleepEngine(3000);
            ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动

        //     var image1Path = RequestEngine.getMntPluginPath() + "xiaoxinxin.png";// 搜索图片
        //     //var image1Path = "/sdcard/xyai/plugin/OS_DYCOMMON/xiaoxinxin.png";// 搜索图片
        //     showLog("image1Path"+image1Path);
        //
        //     var termination=0;
        //     var cehnggong=0;
        //     aaa:while (termination < terminationNum) {
        //         var findsFrom = "finds," + image1Path + "," + 1 + "," + 10;
        //         showLog("findsFrom"+findsFrom);
        //
        //         AccessibilityEngine.sleepEngine(2000);//等待
        //         var msgs = ScreenEngine.currency(findsFrom);
        //         showLog("msgs" + msgs);
        //         var imageJsons = JSON.parse(msgs);
        //
        //         if (AccessibilityEngine.checkUpIdText(widget.pages.fasongxiaoxi.plzf, "评论并转发")==ISTRUE){
        //             showLog("误点评论返回");
        //             i--;
        //             AccessibilityEngine.mockBack();
        //             AccessibilityEngine.sleepEngine(3000);//等待
        //             if ( AccessibilityEngine.checkUpId(widget.pages.tongchengyemian.panduanpinlun ) == ISTRUE){
        //                 showLog("进来就评论");
        //                 AccessibilityEngine.mockBack();
        //                 break;
        //             }
        //         }
        //         if (  AccessibilityEngine.checkUpText("暂无评论") == ISTRUE ){
        //             if ( AccessibilityEngine.checkUpId(widget.pages.tongchengyemian.panduanpinlun ) == ISTRUE) {
        //                 showLog("进来就评论");
        //                 AccessibilityEngine.mockBack();
        //                 break;
        //             }
        //             i--;
        //         }
        //
        //         if (imageJsons.code == 0) {
        //             var n = 0;
        //             for (var a = 0; a < imageJsons.count; a++) {
        //                 showLog(imageJsons.match[n]);
        //                 showLog(imageJsons.match[n + 1]);
        //                 var pressx = imageJsons.match[n] +20;
        //                 var pressy = imageJsons.match[n + 1] +6;
        //                 var zanPress = "press," + pressx + "," + pressy;
        //                 ScreenEngine.currency(zanPress);
        //                 termination++;
        //                 if (termination>=terminationNum){
        //                     if ( AccessibilityEngine.checkUpId(widget.pages.tongchengyemian.panduanpinlun ) == ISTRUE){
        //                         showLog("termination"+termination)
        //                         showLog("点击返回");
        //                         AccessibilityEngine.mockBack();
        //                     }
        //                     break aaa;
        //                 }
        //                 if ( AccessibilityEngine.checkUpText("留下你的精彩评论吧" ) == ISFALSE){
        //                     showLog("留下你的精彩评论吧ISFALSE ");
        //                     AccessibilityEngine.mockBack();
        //                     termination--;
        //                 }
        //                 n = n + 2;
        //             }
        //
        //             if (AccessibilityEngine.checkUpText("暂时没有更多了")==ISTRUE ){
        //                 if ( AccessibilityEngine.checkUpId(widget.pages.tongchengyemian.panduanpinlun) == ISTRUE){
        //                     showLog("termination"+termination)
        //                     showLog("暂时没有更多了点击返回");
        //                     AccessibilityEngine.mockBack();
        //                     break;
        //                 }
        //             }
        //         }
        //         showLog("评论翻页");
        //         ScreenEngine.swipe(parseX(450), parseY(1000), parseX(450), parseY(200), 500);
        //         cehnggong++;
        //         if(cehnggong>30){
        //             showLog("执行成功");
        //             setTaskState("5", "脚本执行完毕");
        //         }
        //     }
        //     if (i>=search-1){
        //         showLog("执行成功");
        //         setTaskState("5", "脚本执行完毕");
        //         throw SyntaxError();
        //     }
        //     //AccessibilityEngine.sleepEngine(2000);//等待
        //     showLog("滑动");
        //     ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
        // }
        //
        // showLog("显示执行成功");
        // setTaskState("5", "脚本执行完毕");
        // throw SyntaxError();
        }
    }
    setTaskState("5", "脚本执行完毕");

}
var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();
